<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

    <title>xmake从入门到精通7：开发和构建Cuda程序</title>
    <meta name="description" content="xmake是一个基于Lua的轻量级现代化c/c++的项目构建工具，主要特点是：语法简单易上手，提供更加可读的项目维护，实现跨平台行为一致的构建体验。本文我们会详细介绍下如何通过xmake来构建cuda程序以及与c/c++程序混合编译。  项目源码  官方文档准备环境首先，我们需要安装NVIDIA提供的Cuda T...">

    
    <meta name="keywords" content="xmake,lua,cuda,tboox" /> 

    <!-- qq oauth -->
    <meta property="qc:admins" content="5211601217706727767255" />

    <!--icon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" sizes="192x192" href="/static/img/nice-highres.png" />
	<link rel="apple-touch-icon-precomposed" href="/static/img/apple-touch-icon-57x57-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/apple-touch-icon-72x72-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/apple-touch-icon-114x114-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/apple-touch-icon-144x144-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/retinahd_icon.png" />
	<meta name="msapplication-TileImage" content="/static/img/retinahd_icon.png" />
	
    <link rel="stylesheet" href=" /css/fontawesome/css/font-awesome.min.css ">
    <link rel="stylesheet" href=" /css/main.css ">
    <link rel="canonical" href="https://tboox.org/cn/2019/11/30/quickstart-7-build-cuda-project/">
    <link rel="alternate" type="application/rss+xml" title="TBOOX Open Source Project" href="https://tboox.org/feed.xml ">
    <link rel="alternate" hreflang="en" href="https://tboox.org/" />
    <link rel="alternate" hreflang="zh-Hans" href="https://tboox.org/cn/" />

    <!-- css -->
    <link href="/css/reward.css" rel="stylesheet" type="text/css"> 




    <script type="text/javascript">
    function isPC(){    
        var userAgentInfo = navigator.userAgent;  
        var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
        var flag = true;    
        for (var v = 0; v < Agents.length; v++) {    
            if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
        }    
        return flag;    
    }
    </script>

<!-- baidu ads -->



    <!-- baidu ads -->

</head>


  <body>

    <header id="top">
    <div class="wrapper">
        <a href="/cn" class="brand">TBOOX</a>
        <button id="headerMenu" class="menu"><i class="fa fa-bars"></i></button>
        <nav id="headerNav">
            <ul>
                <li>
                    
                    <a href="/?lang=0">
                    
                        <i class="fa fa-home"></i>English
                    </a>
                </li>

                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/project/">
                            
                        
                            <i class="fa fa-bookmark"></i>项目
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/archive/">
                            
                        
                            <i class="fa fa-archive"></i>归档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/category/">
                            
                        
                            <i class="fa fa-th-list"></i>分类
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/tag/">
                            
                        
                            <i class="fa fa-tags"></i>标记
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/docs/">
                            
                        
                            <i class="fa fa-book"></i>文档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="https://xmake.io/#/zh-cn/about/contact" target="_blank" >
                            
                        
                            <i class="fa fa-forumbee"></i>社区
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/donation/">
                            
                        
                            <i class="fa fa-heart"></i>捐助
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/about/">
                            
                        
                            <i class="fa fa-user"></i>关于
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            </ul>
        </nav>
    </div>
</header>



        <div class="page clearfix" post>
    <div class="left">
        <h1>xmake从入门到精通7：开发和构建Cuda程序</h1>
        <div class="label">

            <div class="label-card">
                <i class="fa fa-calendar"></i>2019-11-30
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
            


<!-- <span class="point">•</span> -->
<span class="categories">
  <i class="fa fa-th-list"></i>
  
    
        <a href="/category/#xmake" title="Category: xmake" rel="category">xmake</a>
    
  

  <!-- <span class="point">•</span> -->
</span>


            </div>

            <div class="label-card">
            
<!-- <span class="point">•</span> -->
<span class="pageTag">
  <i class="fa fa-tags"></i>
  
    
        <!--a href="/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a-->
        <a href="/cn/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a>&nbsp;
    
        <!--a href="/tag/#lua" title="Tag: lua" rel="tag">lua</a-->
        <a href="/cn/tag/#lua" title="Tag: lua" rel="tag">lua</a>&nbsp;
    
        <!--a href="/tag/#cuda" title="Tag: cuda" rel="tag">cuda</a-->
        <a href="/cn/tag/#cuda" title="Tag: cuda" rel="tag">cuda</a>
    
  

</span>

            </div>

        </div>
        <hr>
        <article itemscope itemtype="http://schema.org/BlogPosting">
        <p>xmake是一个基于Lua的轻量级现代化c/c++的项目构建工具，主要特点是：语法简单易上手，提供更加可读的项目维护，实现跨平台行为一致的构建体验。</p>

<p>本文我们会详细介绍下如何通过xmake来构建cuda程序以及与c/c++程序混合编译。</p>

<ul>
  <li><a href="https://github.com/xmake-io/xmake">项目源码</a></li>
  <li><a href="https://xmake.io/#/zh-cn/">官方文档</a></li>
</ul>

<h3 id="准备环境">准备环境</h3>

<p>首先，我们需要安装NVIDIA提供的Cuda Toolkit SDK工具，其相关说明以及安装文档，可参考官方文档：<a href="http://docs.nvidia.com/cuda/index.html">CUDA Toolkit Documentation</a>。</p>

<p>下载安装好Cuda SDK后，在macosx上会默认安装到<code class="highlighter-rouge">/Developer/NVIDIA/CUDA-x.x</code>目录下，Windows上可以通过<code class="highlighter-rouge">CUDA_PATH</code>的环境变量找到对应的SDK目录，而
Linux下默认会安装到<code class="highlighter-rouge">/usr/local/cuda</code>目录下。</p>

<p>通常，xmake都能自动检测到默认的cuda安装环境，并不需要做任何操作，只需要执行<code class="highlighter-rouge">xmake</code>命令就可以自动完成编译，当然如果找不到SDK，我们也可以手动指定Cuda SDK环境目录：</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> f --cuda=/usr/local/cuda-9.1/ 
</span></code></pre>
</div>

<p>或者通过<code class="highlighter-rouge">xmake g/global</code>命令切到全局设置，避免每次切换编译模式都要重新配置一遍。</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> g --cuda=/usr/local/cuda-9.1/ 
</span></code></pre>
</div>

<p>如果想要测试xmake对当前cuda环境的探测支持，可以直接运行：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake l detect.sdks.find_cuda
<span class="o">{</span> 
  linkdirs <span class="o">=</span> <span class="o">{</span> 
    <span class="s2">"/Developer/NVIDIA/CUDA-10.2/lib/stubs"</span>,
    <span class="s2">"/Developer/NVIDIA/CUDA-10.2/lib"</span> 
  <span class="o">}</span>,
  bindir <span class="o">=</span> <span class="s2">"/Developer/NVIDIA/CUDA-10.2/bin"</span>,
  sdkdir <span class="o">=</span> <span class="s2">"/Developer/NVIDIA/CUDA-10.2"</span>,
  includedirs <span class="o">=</span> <span class="o">{</span> 
    <span class="s2">"/Developer/NVIDIA/CUDA-10.2/include"</span> 
  <span class="o">}</span> 
<span class="o">}</span>
</code></pre>
</div>

<p>大家也可以帮忙贡献相关检测代码<a href="https://github.com/xmake-io/xmake/blob/master/xmake/modules/detect/sdks/find_cuda.lua">find_cuda.lua</a>来改进xmake的检测机制。</p>

<h3 id="创建工程">创建工程</h3>

<p>接下来，我们就可以创建一个空工程来快速体验下了，xmake自带了cuda的工程模板，只需要指定对应的语言即可创建cuda项目：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake create -l cuda <span class="nb">test
</span>create <span class="nb">test</span> ...
  <span class="o">[</span>+]: xmake.lua
  <span class="o">[</span>+]: src/main.cu
  <span class="o">[</span>+]: .gitignore
create ok!
</code></pre>
</div>

<p>默认创建的cuda工程，就是一个最简单的基于Cuda的hello world工程，其源码结构如下：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>├── src
│   └── main.cu
└── ke.lua
</code></pre>
</div>

<p>而xmake.lua里面的内容我们也可以简单看下：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- define target</span>
<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.cu"</span><span class="p">)</span>
    <span class="c1">-- generate SASS code for SM architecture of current host</span>
    <span class="n">add_cugencodes</span><span class="p">(</span><span class="s2">"native"</span><span class="p">)</span>
    <span class="c1">-- generate PTX code for the virtual architecture to guarantee compatibility</span>
    <span class="n">add_cugencodes</span><span class="p">(</span><span class="s2">"compute_30"</span><span class="p">)</span>
</code></pre>
</div>

<p>可以看到，除了最基本的.cu源文件添加，跟其他c/c++项目唯一的区别就是多了个<code class="highlighter-rouge">add_cugencodes()</code>用来设置cuda需要的gencodes，关于这块，下面会详细讲解。</p>

<h3 id="编译项目">编译项目</h3>

<p>工程创建好后，只需要简单的执行xmake即可完成编译。</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake
<span class="o">[</span>00%]: ccache compiling.release src/main.cu
<span class="o">[</span>99%]: devlinking.release test_gpucode.cu.o
<span class="o">[</span>100%]: linking.release <span class="nb">test</span>
</code></pre>
</div>

<p>需要注意的是：从v2.2.7版本开始，xmake默认构建会启用device-link的构建行为，也就是说，现在编译过程中，会额外增加一步device-link过程：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="o">[</span>100%]: devlinking.release test_gpucode.cu.o
</code></pre>
</div>

<p>按照官方的说法，启用device-link设备代码链接的主要优点是可以为您的应用程序提供更传统的代码结构，尤其是在C++中，在现有项目结构不变的前提下，控制每个构建和链接步骤，方便快速的启用GPU代码，实现混合编译。</p>

<p>关于这块可参看NVIDIA的官方描述：<a href="https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/">Separate Compilation and Linking of CUDA C++ Device Code</a>）
如果要禁用device-link的构建逻辑，可以通过<code class="highlighter-rouge">add_values("cuda.devlink", false)</code> 来设置禁用它。</p>

<p>当然，我们也可以尝试直接运行这个cuda程序：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake run
</code></pre>
</div>

<h3 id="项目设置">项目设置</h3>

<p>并且如果设置了里面值为native，那么xmake会自动探测当前主机的cuda设备对应的gencode。</p>

<h4 id="add_cuflags">add_cuflags</h4>

<p>这个接口主要用于添加cu代码相关的编译选项，我们如果还需要一些更加定制化的设置flags，那么就可以调用<code class="highlighter-rouge">add_cuflags</code>来直接设置更加原始的编译选项，就好比c/c++中的<code class="highlighter-rouge">add_cxflags</code>。</p>

<p>例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_cuflags</span><span class="p">(</span><span class="s2">"-gencode arch=compute_30,code=sm_30"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="add_culdflags">add_culdflags</h4>

<p>这个接口主要用于添加cuda设备链接选项，由于上文所说，2.2.7之后，xmake对于cuda程序的默认构建行为会使用device-link，这个阶段如果要设置一些链接flags，则可以通过这个接口来设置。
因为最终的程序链接，会使用ldflags，不会调用nvcc，直接通过gcc/clang等c/c++链接器来链接，所以device-link这个独立的链接阶段的flags设置，通过这个接口来完成。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_culdflags</span><span class="p">(</span><span class="s2">"-gencode arch=compute_30,code=sm_30"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="add_cugencodes">add_cugencodes</h4>

<p><code class="highlighter-rouge">add_cugencodes()</code>接口其实就是对<code class="highlighter-rouge">add_cuflags("-gencode arch=compute_xx,code=compute_xx")</code>编译flags设置的简化封装，其内部参数值对应的实际flags映射关系如下：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="o">-</span> <span class="n">compute_xx</span>                   <span class="c1">--&gt; `-gencode arch=compute_xx,code=compute_xx`</span>
<span class="o">-</span> <span class="n">sm_xx</span>                        <span class="c1">--&gt; `-gencode arch=compute_xx,code=sm_xx`</span>
<span class="o">-</span> <span class="n">sm_xx</span><span class="p">,</span><span class="n">sm_yy</span>                  <span class="c1">--&gt; `-gencode arch=compute_xx,code=[sm_xx,sm_yy]`</span>
<span class="o">-</span> <span class="n">compute_xx</span><span class="p">,</span><span class="n">sm_yy</span>             <span class="c1">--&gt; `-gencode arch=compute_xx,code=sm_yy`</span>
<span class="o">-</span> <span class="n">compute_xx</span><span class="p">,</span><span class="n">sm_yy</span><span class="p">,</span><span class="n">sm_zz</span>       <span class="c1">--&gt; `-gencode arch=compute_xx,code=[sm_yy,sm_zz]`</span>
<span class="o">-</span> <span class="n">native</span>                       <span class="c1">--&gt; match the fastest cuda device on current host,</span>
                                   <span class="n">eg</span><span class="p">.</span> <span class="k">for</span> <span class="n">a</span> <span class="n">Tesla</span> <span class="n">P100</span><span class="p">,</span> <span class="err">`</span><span class="o">-</span><span class="n">gencode</span> <span class="n">arch</span><span class="o">=</span><span class="n">compute_60</span><span class="p">,</span><span class="n">code</span><span class="o">=</span><span class="n">sm_60</span><span class="err">`</span> <span class="n">will</span> <span class="n">be</span> <span class="n">added</span><span class="p">,</span>
                                   <span class="k">if</span> <span class="n">no</span> <span class="n">available</span> <span class="n">device</span> <span class="n">is</span> <span class="n">found</span><span class="p">,</span> <span class="n">no</span> <span class="err">`</span><span class="o">-</span><span class="n">gencode</span><span class="err">`</span> <span class="n">flags</span> <span class="n">will</span> <span class="n">be</span> <span class="n">added</span>
</code></pre>
</div>

<p>例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_cugencodes</span><span class="p">(</span><span class="s2">"sm_30"</span><span class="p">)</span>
</code></pre>
</div>

<p>就等价为</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_cuflags</span><span class="p">(</span><span class="s2">"-gencode arch=compute_30,code=sm_30"</span><span class="p">)</span>
<span class="n">add_culdflags</span><span class="p">(</span><span class="s2">"-gencode arch=compute_30,code=sm_30"</span><span class="p">)</span>
</code></pre>
</div>

<p>是不是上面的更加精简些，这其实就是个用于简化设置的辅助接口。</p>

<p>而如果我们设置了native值，那么xmake会自动探测当前主机的cuda设备，然后快速匹配到它对应的gencode设置，自动追加到整个构建过程中。</p>

<p>例如，如果我们主机目前的GPU是Tesla P100，并且能够被xmake自动检测到，那么下面的设置：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_cugencodes</span><span class="p">(</span><span class="s2">"native"</span><span class="p">)</span>
</code></pre>
</div>

<p>等价于：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_cugencodes</span><span class="p">(</span><span class="s2">"sm_60"</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="cudacc的混合编译">Cuda/C/C++的混合编译</h3>

<p>对于混合编译，我们只需要通过<code class="highlighter-rouge">add_files</code>接口继续加上对应的c/c++代码文件就行了，是不是很简单？</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.cu"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="s2">"src/*.cpp"</span><span class="p">)</span>
    <span class="n">add_cugencodes</span><span class="p">(</span><span class="s2">"native"</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="编译设置">编译设置</h3>

<p>nvcc在编译内部的c/c++代码时候，其实会调用主机环境的c/c++编译器来编译，比如linux下会默认使用gcc/g++，macos下默认使用clang/clang++，windows上默认使用cl.exe。
如果想要让nvcc采用其他的编译器，比如在linux下改用clang作为默认的c/c++编译器，则需要指定<code class="highlighter-rouge">--ccbin=</code>参数设置，这块可以看下：<a href="https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#file-and-path-specifications-compiler-bindir">compiler-ccbin</a></p>

<p>而在xmake中，也对其进行了支持，只需要设置<code class="highlighter-rouge">xmake f --cu-ccbin=clang</code> 就可以切换到其他编译器。</p>

<p>还有两个跟cuda相关的编译参数，我就简单介绍下：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code>xmake f --cu<span class="o">=</span>nvcc --cu-ld<span class="o">=</span>nvcc
</code></pre>
</div>

<p>其中<code class="highlighter-rouge">--cu</code>用来设置.cu代码的编译器，默认就是nvcc，不过clang现在也支持对.cu代码的编译，可以切换设置来尝试，<code class="highlighter-rouge">--cu-ld</code>是设置device-link的链接器，而最终的整体程序link过程，还是用的<code class="highlighter-rouge">--ld</code>来链接的。</p>

        </article>
        <hr>

        <!-- baidu ads -->
        

        <!-- reward -->
        <div style="text-align: center;">
            <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
              <span>赏</span>
            </button>
            <div id="QR" style="display: none;">
                <div id="wechat" style="display: inline-block">
                  <img id="wechat_qr" src="/static/img/weixin.png" alt="WeChat Pay"/>
                  <p>微信打赏</p>
                </div>
                <div id="alipay" style="display: inline-block">
                  <img id="alipay_qr" src="/static/img/alipay.png" alt="Alipay"/>
                  <p>支付宝打赏</p>
                </div>
            </div>
        </div>

        
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
        

        
        
            
        
            
            
            
                
                    
                        
                        <h2 id="similar_posts">相关文章</h2>
                        <ul>
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/17/xmake-update-v2.6.2/">xmake v2.6.2 发布，新增 Linux 内核驱动模块构建支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/03/xmake-update-v2.6.1/">xmake v2.6.1 发布，使用 Lua5.4 运行时，Rust 和 C++ 混合编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/30/xmake-update-v2.5.9/">xmake v2.5.9 发布，改进 C++20 模块，并支持 Nim, Keil MDK 和 Unity Build
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/08/xmake-update-v2.5.8/">xmake v2.5.8 发布，新增 Pascal/Swig 程序和 Lua53 运行时支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/08/29/xmake-update-v2.5.7/">xmake v2.5.7 发布，包依赖锁定和 Vala/Metal 语言编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
            
            
        
        
            </ul>
        

        <div class="post-recent">
    <div class="pre">

        

        

        
        
        <p><strong>上一篇</strong> <a href="/cn/2019/11/21/quickstart-6-build-qt-project/">xmake从入门到精通6：开发和构建Qt程序</a></p>
        
    </div>

    <div class="nex">

        

        

        
        
        <p><strong>下一篇</strong> <a href="/cn/2019/12/05/quickstart-8-switch-build-mode/">xmake从入门到精通8：切换编译模式</a></p>
        
    </div>
</div>


        <h2 id="comments">评论</h2>
        






<div id="gitalk-container"></div>
<link rel="stylesheet" href="/css/gitalk.css">
<script src="/js/gitalk.min.js"></script>

<script>
const gitalk = new Gitalk({
  clientID: '73946dc1d9e2276ad0da',
  clientSecret: '12a3cb94361ba3ebc6ecb68cf80d592bfaa8106d',
  repo: 'tboox.github.io',
  owner: 'waruqi',
  admin: ['waruqi'],
  id: location.pathname,       
  language: 'zh-CN',
  distractionFreeMode: false  
})

gitalk.render('gitalk-container')
</script>





    </div>
    <button class="anchor"><i class="fa fa-anchor"></i></button>
    <div class="right">
        <div class="wrap">

            <!-- codefund ads -->
            

            <!-- Content -->
            <div class="side content">
                <div>
                    内容
                </div>
                <ul id="content-side" class="content-ul">
                    <li><a href="#english">English</a></li>
                    <li><a href="#similar_posts">相关文章</a></li>
                    <li><a href="#comments">评论</a></li>
                </ul>
            </div>


            <!-- baidu ads -->
            
            
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    链接
                </div>
                <ul class="content-ul">
                  <li><a href="http://github.com/waruqi/tbox">tbox</a></li>
                  <li><a href="http://www.xmake.io">xmake</a></li>
                  <li><a href="https://github.com/waruqi">github</a></li>
                </ul>
            </div> 

            <!-- xmake courses -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    xmake 入门课程
                </div>
                <a href="https://xmake.io/#/zh-cn/about/course" target="_blank">
                <img src="/static/img/xmake-course.png" alt="course" width="256" height="193">
                </a>
            </div>

            <!-- qqgroup -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    技术交流群（QQ）
                </div>
                <img src="/static/img/qqgroup.png" alt="qqgroup" width="256" height="284">
            </div> 

            <!-- google ads -->
            

            <!-- baidu ads -->
            

        </div>
    </div>

    <!-- baidu ads -->
    
</div>
<script>
/**
 * target _blank
 */
(function() {
    var aTags = document.querySelectorAll('article a:not([id])')
    for (var i = 0; i < aTags.length; i++) {
        aTags[i].setAttribute('target', '_blank')
    }
}());
</script>
<script src="/js/pageContent.js " charset="utf-8"></script>



    <footer class="site-footer">
    <div class="wrapper">
        <p class="description">
             Copyright (c) 2016-2020 tboox.org 
        </p>
        <p class="contact">
            
            <a href="https://github.com/waruqi" title="GitHub"><i class="fa fa-github" aria-hidden="true"></i></a> 
             
            
            <a href="mailto:waruqi@gmail.com" title="email"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 
            
            
            <a href="https://twitter.com/waruqi" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a> 
            
            <a href="/feed.xml" title="feed"><i class="fa fa-feed" aria-hidden="true"></i></a> 
        </p>
        <p class="power">
            <span>
                Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/Gaohaoyang">HyG</a> & <a href="https://pages.github.com/">Github Pages</a>.
            </span>
        </p>
    </div>
</footer>

    <div class="back-to-top">
    <a href="#top" class="scroll">
        <i class="fa fa-arrow-up" aria-hidden="true"></i>
    </a>
</div>

    <script src=" /js/main.js " charset="utf-8"></script>
    <script src=" /js/scroll.min.js " charset="utf-8"></script>
  </body>

</html>
